<?xml version="1.0" encoding="UTF-8" ?>
<!--  Set system property: -->
<!-- -Dlog4j2.contextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector -->
<!-- to make all loggers asynchronous https://logging.apache.org/log4j/2.x/manual/async.html -->
<Configuration monitorInterval="3600">

    <Properties>
        <Property name="logdir">${sys:catalina.base}/logs</Property>

        <!-- Root Logging-->
        <Property name="rootLoggingLevel">ERROR</Property>

        <!-- Main Package Logging-->
        <Property name="scadaltsOrgLoggingLevel">ERROR</Property>
        <Property name="serotoninComLoggingLevel">ERROR</Property>
        <Property name="seroUtilsLoggingLevel">ERROR</Property>
        <Property name="legacyLoggingLevel">ERROR</Property>

        <!-- Lifecycle Logging-->
        <Property name="startupLoggingLevel">INFO</Property>
        <Property name="backgroundProcessingLoggingLevel">ERROR</Property>
        <Property name="pollingDataSourceLoggingLevel">ERROR</Property>
        <Property name="runtimeManagerLoggingLevel">INFO</Property>

        <!-- Architecture Logging-->
        <Property name="dwrLoggingLevel">ERROR</Property>
        <Property name="apiLoggingLevel">ERROR</Property>
        <Property name="springLoggingLevel">ERROR</Property>
        <Property name="databaseLoggingLevel">ERROR</Property>
        <Property name="springCacheLoggingLevel">ERROR</Property>
        <Property name="quartzLoggingLevel">INFO</Property>

        <!-- Functional Logging-->
        <Property name="scriptLoggingLevel">ERROR</Property>
        <Property name="eventManagerLoggingLevel">ERROR</Property>
        <Property name="modbusLoggingLevel">ERROR</Property>

        <!-- Parse log4j2.xml Logging-->
        <Property name="log4jLoggingLevel">ERROR</Property>
    </Properties>

    <Appenders>

        <Console name="STDOUT" target="SYSTEM_OUT">
            <PatternLayout pattern="%-5p %d{ISO8601} (%C.%M:%L) - %m %n"/>
        </Console>

        <File name="LOG_FILE" filename="${logdir}/mango.log">
            <PatternLayout pattern="%-5p %d{ISO8601} (%C.%M:%L) - %m %n"/>
        </File>

        <File name="LOG_FILE_HISTORY" filename="${logdir}/history.log">
            <PatternLayout pattern="%-5p %d{ISO8601} (%C.%M:%L) - %m %n"/>
        </File>

        <File name="LOG_FILE_MODBUS" filename="${logdir}/modbus.log" append="false">
            <PatternLayout pattern="%-5p %d{ISO8601} (%C.%M:%L) - %m %n"/>
        </File>

        <File name="LOG_FILE_SCRIPTS" filename="${logdir}/scripts.log" append="false">
            <PatternLayout pattern="%-5p %d{ISO8601} (%C.%M:%L) - %m %n"/>
        </File>

        <File name="LOG_FILE_API" filename="${logdir}/api.log" append="false">
            <PatternLayout pattern="%-5p %d{ISO8601} (%C.%M:%L) - %m %n"/>
        </File>

        <File name="LOG_FILE_VIEW_HIERARCHY" filename="${logdir}/viehierarchyservicelogfile.log" append="false">
            <PatternLayout pattern="%-5p %d{ISO8601} (%C.%M:%L) - %m %n"/>
        </File>

        <File name="LOG_FILE_FLYWAY" filename="${logdir}/flyway.log" append="false">
            <PatternLayout pattern="%-5p %d{ISO8601} (%C.%M:%L) - %m %n"/>
        </File>

        <File name="LOG_FILE_SCADA-LTS_DAO" filename="${logdir}/scadaLTSDAO.log" append="false">
            <PatternLayout pattern="%-5p %d{ISO8601} (%C.%M:%L) - %m %n"/>
        </File>

        <File name="LOG_FILE_DAO" filename="${logdir}/dao.log" append="false">
            <PatternLayout pattern="%-5p %d{ISO8601} (%C.%M:%L) - %m %n"/>
        </File>

        <Async name="ASYNC">
            <AppenderRef ref="LOG_FILE"/>
        </Async>

        <Async name="ASYNC_MODBUS">
            <AppenderRef ref="LOG_FILE_MODBUS"/>
        </Async>

        <Async name="ASYNC_FLYWAY">
            <AppenderRef ref="LOG_FILE_FLYWAY"/>
        </Async>

        <Async name="ASYNC_SCRIPT">
            <AppenderRef ref="LOG_FILE_SCRIPTS"/>
        </Async>

        <Async name="ASYNC_DAO">
            <AppenderRef ref="LOG_FILE_DAO"/>
        </Async>

        <Async name="ASYNC_API">
            <AppenderRef ref="LOG_FILE_API"/>
        </Async>

        <Async name="ASYNC_VIEW_HIERARCHY">
            <AppenderRef ref="LOG_FILE_VIEW_HIERARCHY"/>
        </Async>

        <Async name="ASYNC_SCADA-LTS_DAO">
            <AppenderRef ref="LOG_FILE_SCADA-LTS_DAO"/>
        </Async>

    </Appenders>

    <Loggers>
        <!-- Main Package Logging-->
        <!-- Scada-LTS Logging-->
        <Logger name="org.scada_lts" level="${scadaltsOrgLoggingLevel}"/>

        <!-- Serotonin Logging-->
        <Logger name="com.serotonin.mango" level="${serotoninComLoggingLevel}"/>
        <Logger name="com.serotonin.timer" level="${serotoninComLoggingLevel}"/>

        <!-- Legacy Logging-->
        <Logger name="br.org.scadabr" level="${legacyLoggingLevel}"/>
        <Logger name="cc.radiuino.scadabr" level="${legacyLoggingLevel}"/>

        <!-- seroUtils.jar Logging-->
        <Logger name="com.serotonin" level="${seroUtilsLoggingLevel}"/>


        <!-- Lifecycle Logging-->
        <!-- Startup Logging-->
        <Logger name="com.serotonin.mango.MangoContextListener" level="${startupLoggingLevel}"/>

        <Logger name="org.scada_lts.dao.migration" level="${startupLoggingLevel}">
            <AppenderRef ref="ASYNC_FLYWAY"/>
        </Logger>

        <Logger name="org.scada_lts.quartz" level="${startupLoggingLevel}">
            <AppenderRef ref="ASYNC_FLYWAY"/>
        </Logger>

        <Logger name="com.serotonin.mango.db" level="${startupLoggingLevel}">
            <AppenderRef ref="ASYNC_FLYWAY"/>
        </Logger>

        <Logger name="org.flywaydb" level="${startupLoggingLevel}">
            <AppenderRef ref="ASYNC_FLYWAY"/>
        </Logger>

        <!-- BackgroundProcessing Logging-->
        <Logger name="com.serotonin.mango.rt.maint.BackgroundProcessing" level="${backgroundProcessingLoggingLevel}"/>

        <!-- PollingDataSource Logging-->
        <Logger name="com.serotonin.mango.rt.dataSource.PollingDataSource" level="${pollingDataSourceLoggingLevel}"/>


        <!-- Architecture Logging-->
        <!-- Dwr Logging-->
        <Logger name="log_jsp" level="${dwrLoggingLevel}"/>
        <Logger name="org.directwebremoting" level="${dwrLoggingLevel}"/>
        <Logger name="com.serotonin.mango.web.dwr.DataPointEditDwr" level="${dwrLoggingLevel}"/>

        <!-- Spring Logging-->
        <Logger name="org.springframework.web.servlet.FrameworkServlet" level="${springLoggingLevel}"/>

        <!-- Spring Cache Logging-->
        <Logger name="org.springframework.cache" level="${springCacheLoggingLevel}" />

        <!-- Database Logging-->
        <Logger name="com.serotonin.db.spring.ExtendedJdbcTemplate" level="${databaseLoggingLevel}"/>

        <Logger name="org.scada_lts.dao" level="${databaseLoggingLevel}">
            <AppenderRef ref="ASYNC_SCADA-LTS_DAO"/>
        </Logger>

        <Logger name="org.scada_lts.dao.alarms.PlcAlarmsDAO" level="${databaseLoggingLevel}">
            <AppenderRef ref="ASYNC_SCADA-LTS_DAO"/>
        </Logger>

        <Logger name="com.serotonin.mango.db.dao" level="${databaseLoggingLevel}">
            <AppenderRef ref="ASYNC_FLYWAY"/>
        </Logger>

        <Logger name="com.serotonin.mango.db.dao.DataSourceDao" level="${databaseLoggingLevel}">
            <AppenderRef ref="ASYNC_DAO"/>
        </Logger>

        <!-- RuntimeManager Logging-->
        <Logger name="com.serotonin.mango.rt.RuntimeManager" level="${runtimeManagerLoggingLevel}"/>

        <!-- API Logging-->
        <Logger name="org.scada_lts.service" level="${apiLoggingLevel}">
            <AppenderRef ref="ASYNC_API"/>
        </Logger>

        <Logger name="org.scada_lts.web.mvc.api" level="${apiLoggingLevel}">
            <AppenderRef ref="ASYNC_API"/>
        </Logger>

        <!-- Quartz Logging-->
        <Logger name="org.scada_lts.quartz" level="${quartzLoggingLevel}"/>
        <Logger name="org.quartz" level="${quartzLoggingLevel}"/>

        <!-- Functional Logging-->
        <!-- Event Logging-->
        <Logger name="com.serotonin.mango.rt.EventManager" level="${eventManagerLoggingLevel}"/>

        <!-- Script Logging-->
        <Logger name="com.serotonin.mango.rt.dataSource.meta.MetaPointLocatorRT" level="${scriptLoggingLevel}" >
            <AppenderRef ref="ASYNC_SCRIPT"/>
        </Logger>
        <Logger name="com.serotonin.mango.rt.link.PointLinkRT" level="${scriptLoggingLevel}" >
            <AppenderRef ref="ASYNC_SCRIPT"/>
        </Logger>
        <Logger name="com.serotonin.mango.rt.event.handlers.ScriptHandlerRT" level="${scriptLoggingLevel}" >
            <AppenderRef ref="ASYNC_SCRIPT"/>
        </Logger>

        <Logger name="br.org.scadabr.web.dwr.ScriptsDwr" level="${scriptLoggingLevel}" >
            <AppenderRef ref="ASYNC_SCRIPT"/>
        </Logger>
        <Logger name="com.serotonin.mango.web.dwr.DataSourceEditDwr" level="${scriptLoggingLevel}" >
            <AppenderRef ref="ASYNC_SCRIPT"/>
        </Logger>
        <Logger name="com.serotonin.mango.web.dwr.ViewDwr" level="${scriptLoggingLevel}" >
            <AppenderRef ref="ASYNC_SCRIPT"/>
        </Logger>
        <Logger name="com.serotonin.mango.web.dwr.PointLinksDwr" level="${scriptLoggingLevel}" >
            <AppenderRef ref="ASYNC_SCRIPT"/>
        </Logger>

        <Logger name="org.scada_lts.web.mvc.controller.ScriptController" level="${scriptLoggingLevel}" >
            <AppenderRef ref="ASYNC_SCRIPT"/>
        </Logger>
        <Logger name="org.scada_lts.mango.service.PointValueService" level="${scriptLoggingLevel}" >
            <AppenderRef ref="ASYNC_SCRIPT"/>
        </Logger>
        <Logger name="com.serotonin.mango.view.component.ScriptComponent" level="${scriptLoggingLevel}" >
            <AppenderRef ref="ASYNC_SCRIPT"/>
        </Logger>

        <!-- Modbus Logging-->
        <Logger name="com.serotonin.modbus4j.ip.listener" level="${modbusLoggingLevel}">
            <AppenderRef ref="ASYNC_MODBUS"/>
        </Logger>

        <!-- Parse log4j2.xml Logging-->
        <Logger name="org.apache.log4j.xml" level="${log4jLoggingLevel}">
            <AppenderRef ref="ASYNC"/>
        </Logger>

        <Root level="${rootLoggingLevel}">
            <AppenderRef ref="STDOUT"/>
            <AppenderRef ref="ASYNC"/>
        </Root>
    </Loggers>

</Configuration>